<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      class="customTable"
      @selection-change="handleSelectionChange"
      v-loading="loading"
      :height="height"
    >
      <el-table-column v-if="select" type="selection" width="55" />
      <el-table-column v-if="index" type="index" width="55" label="序号" />
      <el-table-column v-if="expand" type="expand" show-overflow-tooltip>
        <template #default="{$index}">
          <slot name="expand" :index="$index"></slot>
        </template>
      </el-table-column>
      <el-table-column
        v-for="column in columns"
        :key="column.prop"
        :prop="column.prop"
        :label="column.label"
        :width="column.width"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <!-- 这里是自定义单元格内容的插槽位置 -->
          <slot :name="`${column.prop}`" :row="scope.row"></slot>
          <!-- 如果没有自定义插槽，则显示默认内容 -->
          <span v-if="!$slots[`custom-${column.prop}`]">{{
            scope.row[column.prop]
          }}</span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'CustomTable',
  props: {
    columns: Array,
    tableData: Array,
    select: Boolean,
    index: Boolean,
    handleSelectionChange: {
      type: Function,
      default: () => () => {},
      require: false
    },
    loading: Boolean,
    height: String,
    expand: {
      type: Boolean,
      default: false,
      require: false
    }
  }
}
</script>

<style scoped></style>
